# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=mintty
pkgver=3.2.0
pkgrel=1
epoch=1
pkgdesc="Terminal emulator with native Windows look and feel"
arch=('i686' 'x86_64')
license=('GPL3')
groups=('base')
depends=('sh')
url="https://mintty.github.io"
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/mintty/mintty/archive/${pkgver}.tar.gz
        0001-add-msys2-launcher.patch
        0002-fix-current-dir-inheritance-for-alt-f2-on-msys2.patch)
sha256sums=('5423320eea63aff00e3a10924848323466075381ac1e7ea925356af3fe771528'
            '7f7475e8a8e3b15319b95cabed856e941ddfdbc31ca09b47ce0f25ffb22aeb03'
            'de398d6ca166ebeb44ab1c23e3759ec5d2d13e2241360d6a06c918c611e62830')

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  del_file_exists src/launcher.c src/launcher.h
  patch -p1 -i ${srcdir}/0001-add-msys2-launcher.patch
  patch -p1 -i ${srcdir}/0002-fix-current-dir-inheritance-for-alt-f2-on-msys2.patch
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  mkdir -p ${pkgdir}/usr/{bin,share}
  mkdir -p ${pkgdir}/usr/share/man/man1
  mkdir -p ${pkgdir}/usr/share/licenses/${pkgname}
  mkdir -p ${pkgdir}/usr/share/${pkgname}/lang
  mkdir -p ${pkgdir}/usr/share/${pkgname}/themes

  install -m755 bin/mintty.exe ${pkgdir}/usr/bin/mintty.exe
  install -m755 tools/* ${pkgdir}/usr/bin/
  install -m644 docs/mintty.1 ${pkgdir}/usr/share/man/man1/mintty.1

  install -m644 LICENSE ${pkgdir}/usr/share/licenses/${pkgname}/
  install -m644 LICENSE.Oxygen ${pkgdir}/usr/share/licenses/${pkgname}/
  install -m644 LICENSE.PuTTY ${pkgdir}/usr/share/licenses/${pkgname}/

  install -m644 lang/messages.pot ${pkgdir}/usr/share/${pkgname}/lang/
  install -m644 lang/*.po ${pkgdir}/usr/share/${pkgname}/lang/

  install -m644 themes/* ${pkgdir}/usr/share/${pkgname}/themes/
}
